﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace library
{
    public partial class login : Form
    {
        public MySqlConnection conn = new DBclass().getConn();
        public login()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            conn.Open();
            string username = textBox1.Text;
            string userpwd = textBox2.Text;
            string sql = "select * from user_info where uID=@id and upwd=@pwd";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.Parameters.Add("@id", MySqlDbType.Int32).Value = username;
            cmd.Parameters.Add("@pwd", MySqlDbType.VarChar,10).Value = userpwd;
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                Form f = new umain();
                f.Show();
                User.uID = (int)reader["uID"];
                User.identity = reader["identity"].ToString();
                User.uname=reader["uname"].ToString();
                User.college = reader["college"].ToString();
                User.major=reader["major"].ToString();
            }
            else
            {
                MessageBox.Show("登录失败");
            }
            conn.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            conn.Open();
            string username = textBox1.Text;
            string userpwd = textBox2.Text;
            string sql = "select * from admin_info where aID=@aID and apwd=@apwd";
            MySqlCommand cmd = new MySqlCommand(sql, conn);
            cmd.Parameters.Add("@aID", MySqlDbType.Int32).Value = username;
            cmd.Parameters.Add("@apwd", MySqlDbType.VarChar, 10).Value = userpwd;
            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                Form f = new amain();
                User.uID = (int)reader["aID"];
                f.Show();
            }
            else
            {
                MessageBox.Show("登录失败");
            }
            conn.Close();
        }

        private void 登录界面_Load(object sender, EventArgs e)
        {

        }
    }
}
